/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import VIEW.OLD.Returns;
import BEANS.Product;
import BEANS.SecondHandProduct;
import CONTROLLERS.UserController;
import UTIL.DatabaseConnector;
import java.awt.CardLayout;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.swing.JOptionPane;
/**
 *
 * @author Belthazod
 */
public class Main extends javax.swing.JFrame {
    
   
   
    CardLayout card;
    UserController userController;
    static String user = "";
    /**
     * Creates new form main
     */
    public Main() {
        initComponents();
        initialize();
        try{
        SupplierUI.updateSupplierTable();  
        Category.updateCategoryTable();
        ProductsUI.updateAdminProductsTable();      
        UserUI.updateUsersTable();
        //ReplacementUI.updateReturnsHistoryTable();
        ViewSecondHandList.updateSecondHandListTable();
        //TradeProduct.updateTradeInHistory();
        NewReturns.updateDefectiveItemsTable();
        Reports.updateInventoryTable();
        userController = new UserController(oldUserPasswordInput, newUserPasswordInput, newUserConfirmPasswordInput,editPasswordDialog, userLabel);
        }catch(Exception e){
            
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        editPasswordDialog = new javax.swing.JDialog();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        userLabel = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        oldUserPasswordInput = new javax.swing.JPasswordField();
        newUserPasswordInput = new javax.swing.JPasswordField();
        newUserConfirmPasswordInput = new javax.swing.JPasswordField();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        adminAccessDialog = new javax.swing.JDialog();
        jLabel10 = new javax.swing.JLabel();
        adminPasswordInput = new javax.swing.JPasswordField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        adminUserNameInput = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        reportsMenuButton = new javax.swing.JButton();
        tradeInMenuButton = new javax.swing.JButton();
        warrantyMenuButton = new javax.swing.JButton();
        transferMenuButton = new javax.swing.JButton();
        salesMenuButton = new javax.swing.JButton();
        returnsMenuButton = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jButton13 = new javax.swing.JButton();
        cardWindow = new javax.swing.JPanel();
        inventoryUI1 = new VIEW.InventoryUI();
        deliveryUI1 = new VIEW.DeliveryUI();
        transferUI1 = new VIEW.TransferUI();
        replacementUI1 = new VIEW.ReplacementUI();
        tradeInNew1 = new VIEW.TradeInNew();
        newReturns1 = new VIEW.NewReturns();
        reports1 = new VIEW.Reports();
        adminUI1 = new VIEW.AdminUI();
        adminMenuButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        userView = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        deliveryMenuButton = new javax.swing.JButton();

        editPasswordDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        editPasswordDialog.setTitle("Change User Password");
        editPasswordDialog.setBounds(new java.awt.Rectangle(0, 0, 400, 300));
        editPasswordDialog.setMinimumSize(new java.awt.Dimension(450, 225));
        editPasswordDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        editPasswordDialog.setLocationRelativeTo(null);
        editPasswordDialog.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                editPasswordDialogWindowClosed(evt);
            }
        });
        editPasswordDialog.getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel3.setText("Username:");
        editPasswordDialog.getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel4.setText("Old Password:");
        editPasswordDialog.getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 63, -1, -1));

        userLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        userLabel.setText("user");
        editPasswordDialog.getContentPane().add(userLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 20, -1, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel5.setText("New Password:");
        editPasswordDialog.getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 107, -1, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel6.setText("Confirm New Password:");
        editPasswordDialog.getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 151, -1, -1));

        oldUserPasswordInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        oldUserPasswordInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oldUserPasswordInputActionPerformed(evt);
            }
        });
        oldUserPasswordInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                oldUserPasswordInputKeyPressed(evt);
            }
        });
        editPasswordDialog.getContentPane().add(oldUserPasswordInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(221, 60, 189, -1));

        newUserPasswordInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        newUserPasswordInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                newUserPasswordInputKeyPressed(evt);
            }
        });
        editPasswordDialog.getContentPane().add(newUserPasswordInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 100, 189, -1));

        newUserConfirmPasswordInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        newUserConfirmPasswordInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                newUserConfirmPasswordInputKeyPressed(evt);
            }
        });
        editPasswordDialog.getContentPane().add(newUserConfirmPasswordInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 140, 190, -1));

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setText("Save");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        editPasswordDialog.getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 200, -1, -1));

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setText("Cancel");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        editPasswordDialog.getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 200, -1, -1));

        adminAccessDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        adminAccessDialog.setTitle("Aministrator Privilege Needed");
        adminAccessDialog.setBounds(new java.awt.Rectangle(0, 0, 400, 140));
        adminAccessDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        adminAccessDialog.setLocationRelativeTo(null);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel10.setText("Password:");

        adminPasswordInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        adminPasswordInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                adminPasswordInputKeyPressed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton4.setText("Ok");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton5.setText("Cancel");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel11.setText("Admin:");

        adminUserNameInput.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout adminAccessDialogLayout = new javax.swing.GroupLayout(adminAccessDialog.getContentPane());
        adminAccessDialog.getContentPane().setLayout(adminAccessDialogLayout);
        adminAccessDialogLayout.setHorizontalGroup(
            adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(adminAccessDialogLayout.createSequentialGroup()
                .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, adminAccessDialogLayout.createSequentialGroup()
                        .addGap(188, 188, 188)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5))
                    .addGroup(adminAccessDialogLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel10))
                        .addGap(18, 18, 18)
                        .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(adminPasswordInput, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                            .addComponent(adminUserNameInput))))
                .addContainerGap())
        );
        adminAccessDialogLayout.setVerticalGroup(
            adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, adminAccessDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(adminUserNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
                .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(adminPasswordInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(adminAccessDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 102));
        setIconImages(null);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 102, 153));
        jPanel1.setPreferredSize(new java.awt.Dimension(1024, 768));

        reportsMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/reports_hover.png"))); // NOI18N
        reportsMenuButton.setBorderPainted(false);
        reportsMenuButton.setContentAreaFilled(false);
        reportsMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/reports_yellow.png"))); // NOI18N
        reportsMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportsMenuButtonActionPerformed(evt);
            }
        });

        tradeInMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/tradein_hover.png"))); // NOI18N
        tradeInMenuButton.setBorderPainted(false);
        tradeInMenuButton.setContentAreaFilled(false);
        tradeInMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/tradein.png"))); // NOI18N
        tradeInMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tradeInMenuButtonActionPerformed(evt);
            }
        });

        warrantyMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/replacements_hover.png"))); // NOI18N
        warrantyMenuButton.setBorderPainted(false);
        warrantyMenuButton.setContentAreaFilled(false);
        warrantyMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/replacements_yellow.png"))); // NOI18N
        warrantyMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                warrantyMenuButtonActionPerformed(evt);
            }
        });

        transferMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/transfer_hover.png"))); // NOI18N
        transferMenuButton.setBorderPainted(false);
        transferMenuButton.setContentAreaFilled(false);
        transferMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/transfer_yellow.png"))); // NOI18N
        transferMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferMenuButtonActionPerformed(evt);
            }
        });

        salesMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/sales_hover.png"))); // NOI18N
        salesMenuButton.setBorderPainted(false);
        salesMenuButton.setContentAreaFilled(false);
        salesMenuButton.setPreferredSize(new java.awt.Dimension(100, 83));
        salesMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/sales_1.png"))); // NOI18N
        salesMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salesMenuButtonActionPerformed(evt);
            }
        });

        returnsMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/returns-hover.png"))); // NOI18N
        returnsMenuButton.setBorder(null);
        returnsMenuButton.setBorderPainted(false);
        returnsMenuButton.setContentAreaFilled(false);
        returnsMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/returns.png"))); // NOI18N
        returnsMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                returnsMenuButtonActionPerformed(evt);
            }
        });

        jPanel4.setForeground(new java.awt.Color(255, 255, 255));
        jPanel4.setOpaque(false);

        jButton13.setBackground(new java.awt.Color(31, 37, 61));
        jButton13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton13.setForeground(new java.awt.Color(255, 255, 255));
        jButton13.setText("Logout");
        jButton13.setBorderPainted(false);
        jButton13.setContentAreaFilled(false);
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        cardWindow.setBackground(new java.awt.Color(102, 102, 102));
        cardWindow.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cardWindow.setLayout(new java.awt.CardLayout());
        cardWindow.add(inventoryUI1, "inventoryCard");
        cardWindow.add(deliveryUI1, "deliveryCard");
        cardWindow.add(transferUI1, "transferCard");
        cardWindow.add(replacementUI1, "replacementCard");
        cardWindow.add(tradeInNew1, "tradeCard");
        cardWindow.add(newReturns1, "NewreturnsCard");
        cardWindow.add(reports1, "reportsCard");
        cardWindow.add(adminUI1, "adminCard");

        adminMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/adminkey.png"))); // NOI18N
        adminMenuButton.setBorderPainted(false);
        adminMenuButton.setContentAreaFilled(false);
        adminMenuButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                adminMenuButtonMouseClicked(evt);
            }
        });
        adminMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adminMenuButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Change Password");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        userView.setFont(new java.awt.Font("Tempus Sans ITC", 0, 18)); // NOI18N
        userView.setForeground(new java.awt.Color(204, 204, 204));
        userView.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        userView.setText("123");
        userView.setToolTipText("");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(cardWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 1100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(userView, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(adminMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton13)))
                .addContainerGap(560, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(userView))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1))
                            .addComponent(adminMenuButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cardWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 665, Short.MAX_VALUE))
        );

        card = (CardLayout)cardWindow.getLayout();

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/bg.jpg"))); // NOI18N

        deliveryMenuButton.setBackground(new java.awt.Color(31, 37, 61));
        deliveryMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/delivery_hover.png"))); // NOI18N
        deliveryMenuButton.setToolTipText("");
        deliveryMenuButton.setBorderPainted(false);
        deliveryMenuButton.setContentAreaFilled(false);
        deliveryMenuButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/UI ICONS/delivery_yellow.png"))); // NOI18N
        deliveryMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deliveryMenuButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(deliveryMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(transferMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(salesMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tradeInMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(warrantyMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(returnsMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reportsMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 1317, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(salesMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(transferMenuButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deliveryMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tradeInMenuButton)
                .addGap(16, 16, 16)
                .addComponent(warrantyMenuButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(returnsMenuButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(reportsMenuButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 742, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1286, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 726, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void salesMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salesMenuButtonActionPerformed
        card.show(cardWindow, "inventoryCard");
    }//GEN-LAST:event_salesMenuButtonActionPerformed

    private void adminMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adminMenuButtonActionPerformed
        DatabaseConnector dbConnector = DatabaseConnector.getInstance();
        try{
        String name = userView.getText();
        boolean isAdmin = false;
        ResultSet rs = dbConnector.query("SELECT type FROM USERS where name = '"+ name +"'");
            while(rs.next()){
                String userType = rs.getString(1);
                
                if(userType.equals("admin")){
                       isAdmin = true;  
                       break;                       
            }else{
                isAdmin = false;
            }
            }
            
            if(isAdmin){
                card.show(cardWindow, "adminCard");
                    adminAccessDialog.dispose();
                    adminUserNameInput.setText("");
                    adminPasswordInput.setText("");
            }else{
                adminAccessDialog.setVisible(true);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_adminMenuButtonActionPerformed

    private void transferMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferMenuButtonActionPerformed
        card.show(cardWindow, "transferCard");
    }//GEN-LAST:event_transferMenuButtonActionPerformed

    private void warrantyMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_warrantyMenuButtonActionPerformed
        card.show(cardWindow, "replacementCard");
    }//GEN-LAST:event_warrantyMenuButtonActionPerformed

    private void tradeInMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tradeInMenuButtonActionPerformed
        card.show(cardWindow, "tradeCard");
    }//GEN-LAST:event_tradeInMenuButtonActionPerformed

    private void reportsMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportsMenuButtonActionPerformed
        card.show(cardWindow, "reportsCard");
    }//GEN-LAST:event_reportsMenuButtonActionPerformed

    private void returnsMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_returnsMenuButtonActionPerformed
         card.show(cardWindow, "NewreturnsCard");
    }//GEN-LAST:event_returnsMenuButtonActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        int x = JOptionPane.showConfirmDialog(null, "Confirm Logout", "Warning", JOptionPane.OK_CANCEL_OPTION);
        
        if(x ==0){this.dispose();
            UserLogIn uli = new UserLogIn();
            uli.setLocationRelativeTo(null);
            uli.setVisible(true);
        }
    }//GEN-LAST:event_jButton13ActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        editPasswordDialog.setVisible(true);
    }//GEN-LAST:event_jLabel1MouseClicked

    private void oldUserPasswordInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oldUserPasswordInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_oldUserPasswordInputActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        userController.changeUserPassword();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        oldUserPasswordInput.setText("");
        newUserPasswordInput.setText("");
        newUserConfirmPasswordInput.setText("");
        editPasswordDialog.dispose();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void adminMenuButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_adminMenuButtonMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_adminMenuButtonMouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DatabaseConnector dbConnector = DatabaseConnector.getInstance();
        try{
            String un = adminUserNameInput.getText();
            String pas = new String(adminPasswordInput.getPassword());
            String pass = "";
            boolean adminFound = false;
            ResultSet rs = dbConnector.query("SELECT username, password FROM users WHERE type = 'admin';");            
            while(rs.next()){
                user = rs.getString("username");
                pass = rs.getString("password"); 
                
                if(user.equals(un) && pass.equals(pas)){
                       adminFound = true;  
                       break;                       
            }else{
                adminFound = false;
            }
            }

            if(adminFound){
                card.show(cardWindow, "adminCard");
                    adminAccessDialog.dispose();
                    adminUserNameInput.setText("");
                    adminPasswordInput.setText("");  
                    UserUI.setUser(user);
            }else{
                JOptionPane.showMessageDialog(null, "The admin username or password that you have entered is wrong.", "Incorrect username / password",JOptionPane.ERROR_MESSAGE);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        adminAccessDialog.dispose();
        
    }//GEN-LAST:event_jButton5ActionPerformed

    private void adminPasswordInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_adminPasswordInputKeyPressed
        
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon.png")));
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton4.doClick();
	}
    }//GEN-LAST:event_adminPasswordInputKeyPressed

    private void oldUserPasswordInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_oldUserPasswordInputKeyPressed
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton2.doClick();
	}
    }//GEN-LAST:event_oldUserPasswordInputKeyPressed

    private void newUserPasswordInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_newUserPasswordInputKeyPressed
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton2.doClick();
	}
    }//GEN-LAST:event_newUserPasswordInputKeyPressed

    private void newUserConfirmPasswordInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_newUserConfirmPasswordInputKeyPressed
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton2.doClick();
	}
    }//GEN-LAST:event_newUserConfirmPasswordInputKeyPressed

    private void deliveryMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deliveryMenuButtonActionPerformed
        card.show(cardWindow, "deliveryCard");
    }//GEN-LAST:event_deliveryMenuButtonActionPerformed

    private void editPasswordDialogWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_editPasswordDialogWindowClosed
        oldUserPasswordInput.setText("");
        newUserPasswordInput.setText("");
        newUserConfirmPasswordInput.setText("");
    }//GEN-LAST:event_editPasswordDialogWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

        static ArrayList<Product> productList = new ArrayList<Product>();
        static ArrayList<SecondHandProduct> secondHandList = new ArrayList<SecondHandProduct>();                                    

    
    public static void setUser(String name){
        userView.setText(name);
    }
    
    public static void setUserName (String username){
        userLabel.setText(username);
    }
    
    public static void setCurrentUser(String userValue){
        user = userValue;
    }
    
    public static String getUser(){
        return user;
    }
    
    public static String getNameValue(){
        return userLabel.getText();
    }
       
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /* Create and display the form */
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
                
            }
        });
    
        
        
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog adminAccessDialog;
    private javax.swing.JButton adminMenuButton;
    private javax.swing.JPasswordField adminPasswordInput;
    private VIEW.AdminUI adminUI1;
    private javax.swing.JTextField adminUserNameInput;
    private javax.swing.JPanel cardWindow;
    private javax.swing.JButton deliveryMenuButton;
    private VIEW.DeliveryUI deliveryUI1;
    private javax.swing.JDialog editPasswordDialog;
    private VIEW.InventoryUI inventoryUI1;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private VIEW.NewReturns newReturns1;
    private javax.swing.JPasswordField newUserConfirmPasswordInput;
    private javax.swing.JPasswordField newUserPasswordInput;
    private javax.swing.JPasswordField oldUserPasswordInput;
    private VIEW.ReplacementUI replacementUI1;
    private VIEW.Reports reports1;
    private javax.swing.JButton reportsMenuButton;
    private javax.swing.JButton returnsMenuButton;
    private javax.swing.JButton salesMenuButton;
    private javax.swing.JButton tradeInMenuButton;
    private VIEW.TradeInNew tradeInNew1;
    private javax.swing.JButton transferMenuButton;
    private VIEW.TransferUI transferUI1;
    private static javax.swing.JLabel userLabel;
    private static javax.swing.JLabel userView;
    private javax.swing.JButton warrantyMenuButton;
    // End of variables declaration//GEN-END:variables

    private void initialize() {
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon.png")));
        this.setTitle("Ocampo's Battery Trading & Tire Supply and Repair Shop");
    }
}
